package com.md.application.service;

import com.md.api.InternalApi;
import com.md.domain.model.po.AppInfoPO;
import com.md.domain.model.po.ModulePO;
import com.md.domain.service.AppDomainService;
import com.md.model.system.CommonResult;
import com.md.value.AppTypeEnum;
import com.md.value.ModuleTypeEnum;
import com.md.value.constants.DefaultServerContext;
import com.md.value.server.ServerContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 刘骄阳
 * 2023-08-08 14:15
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class InternalApplicationService implements InternalApi {

  private final AppDomainService appDomainService;

  @Override
  public CommonResult<Void> init() {
    ServerContext.put(DefaultServerContext.BRAND_ID, 1L);
    ServerContext.put(DefaultServerContext.TENANT_ID, 1L);
    ServerContext.put(DefaultServerContext.USER_ID, 1L);
    ModulePO module = new ModulePO();
    module.setModelName("系统");
    module.setBrandId(1L);
    module.setTenantId(1L);
    module.setUserId("1");
    module.setModelEnName("system");
    module.setModuleType(ModuleTypeEnum.PUBLIC.getCode());
    appDomainService.createModule(module);
    AppInfoPO appInfoPO = new AppInfoPO();
    appInfoPO.setUserId("system");
    appInfoPO.setAppName("系统中心");
    appInfoPO.setAppCode("SC");
    appInfoPO.setAppEnName("system");
    appInfoPO.setTenantId(1L);
    appInfoPO.setBrandId(1L);
    appInfoPO.setAppType(AppTypeEnum.PUBLIC.getCode());
    appDomainService.createAppInfo(appInfoPO, module.getId());
    return CommonResult.success();
  }
}
